package com.b511.swpu.cementbackend.controller;

import com.b511.swpu.cementbackend.dto.input.SysCompanyInputDto;
import com.b511.swpu.cementbackend.service.SysCompanyService;
import com.b511.swpu.cementbackend.util.R;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

@Api(value = "公司单位", tags = {"公司单位"})
@RestController
@RequestMapping("/company")
public class SysCompanyController {

    private final SysCompanyService sysCompanyService;

    public SysCompanyController(SysCompanyService sysCompanyService) {
        this.sysCompanyService = sysCompanyService;
    }

    @GetMapping()
    public R getCompany() {
        return sysCompanyService.getSysCompany();
    }

    @PutMapping("/{code}")
    public R updateCompany(@PathVariable String code, @RequestBody SysCompanyInputDto sysCompanyInputDto) {
        return sysCompanyService.updateSysCompanyName(code, sysCompanyInputDto);
    }

    @DeleteMapping("/{code}")
    public R deleteCompany(@PathVariable String code) {
        return sysCompanyService.deleteSysCompany(code);
    }

    @PostMapping("/{code}")
    public R postCompany(@PathVariable String code, @RequestBody SysCompanyInputDto sysCompanyInputDto){
        return sysCompanyService.addChildSysCompany(code, sysCompanyInputDto);
    }
}
